package cn.joker.constant;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class PageResult<T> {
    /**
     * 当前页码
     */
    private Integer pageNum;
    
    /**
     * 每页数量
     */
    private Integer pageSize;
    
    /**
     * 总记录数
     */
    private Long total;
    
    /**
     * 总页数
     */
    private Integer pages;
    
    /**
     * 分页数据列表
     */
    private List<T> list;
    
    /**
     * 从MyBatis-Plus的Page对象转换
     */
    public PageResult(Page<T> page) {
        this.pageNum = (int) page.getCurrent();
        this.pageSize = (int) page.getSize();
        this.total = page.getTotal();
        this.pages = (int) page.getPages();
        this.list = page.getRecords();
    }
}